package com.quwan.security.user;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotNull;
import java.util.Collection;

/**
 * @author quan
 * @date 2021-06-06 16:03
 */
public class JwtUserDetails implements UserDetails {
    /**
     * id
     */
    private final String id;
    /**
     * userName app对应手机 后台对应登录账号
     */
    private final String username;
    /**
     * password 对应数据库用户 password
     */
    private final String password;

    private final String module;

//    private final Object token;

    @NotNull
    public static JwtUserDetails I(String id, String userName, String password,String module) {
        return new JwtUserDetails(id, userName, password,module);
    }

    private JwtUserDetails(String id, String username, String password,String module) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.module = module;
    }

    @JsonIgnore
    public String getId() {
        return id;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }

    public String getModule() {
        return module;
    }

}
